Assistant Tool With Interactive UI PRO
AssistantTool supports interactive UI tools that render custom in-tool interfaces and return structured results after user interaction.
This mode is useful when the Assistant needs user decisions that cannot be expressed reliably as plain text, such as option selection, confirmation details, staged forms, or visual previews.
1. Configuration in assistant_tool.json
To enable interactive UI rendering:
Key fields
-
supportsUIRender: trueThe tool is expected to provide a UI renderer viaAssistantTool.registerUIView(...). -
keepRenderingAfterCompleteControls whether the UI should remain rendered afterresponse(...)returns the result.
2. Registration API
Interactive UI tools register a function component:
Where view receives:
The component should render synchronously and return a VirtualNode.
3. Returning Results from UI
Use response(result) when the user completes interaction.
Notes:
responsecan be called only once; later calls are ignored.userPartsare shown to users.assistantPartsare sent back to the Assistant for reasoning.
4. State Management During UI Interaction
Interactive UI tools can persist state per tool call:
State is JSON-serializable and persisted with tool-call history.
Typical uses:
- selected options
- current step index
- temporary form values
- partial progress flags
5. Relationship with Approval
If requireApproval: true and supportsUIRender: true:
- Approval request flow runs first
- If approved, UI renderer is invoked
- If rejected, renderer is not invoked
This keeps sensitive operations controllable while still allowing rich interaction after consent.
6. Auto-Approve Behavior
isAutoApprove is passed to UIProps.
Use it when your tool can safely skip interaction in specific cases and return immediately:
7. Minimal Example
8. Testing UI Tools
registerUIView returns a UI test function:
In test mode:
- UI is rendered in a preview panel
- close action returns a cancellation result
- optional screenshot capture is supported
9. Recommended Practices
- Keep UI compact; it is embedded inside the tool container.
- Prefer card-style layouts over large scrolling containers.
- Return concise
assistantPartswith stable structure. - Use
userPartsfor user-facing summaries. - Persist only state needed to restore interaction.
- Avoid heavy side effects inside render functions.
